flyList = {};
flyList.init = function(){
    //  var flyListDateShow = iG.getObjItem("flyList_win","flyListDateShow");
    var date = JSON.parse(getStorage("data")).time;
    var dateArr = date.split("-");
    flyList.setDate(dateArr[0], dateArr[1], dateArr[2]);
    $("#date").removeClass("uhide");
    $("#date>div").on("click", flyList.selectDate);
};


//插入数据
flyList.append = function(data){
    var html = $('<li class="ubb pr uhide" style="border-color:#a0a0a0">' +
    '<section class="pt101 pr5 pb101 pl5" basicInfo>' +
    '<div class="ub ub-ac">' +
    '<div class="ub-img mr6" icon></div>' +
    '<div class="c2 fs101" auto="carrier" style="font-weight:600">——</div>' +
    '<div class="c2 fs101" auto="flightNo" style="font-weight:600">——</div>' +
    '<div class="c2 ml3 mr3 uhide">/</div>' +
    '<div class="ub-f1 c31 fs9 ml8 " auto="fleetCode" style="font-family: arial;">——</div>' +
    '<div class="ub-f1 c31 fs9 ml8 uhide" flightDate style="font-family: arial;"></div>' +
    '<div class="ub-f1"></div>' +
    '<div class="ub ub-ac mr16" tickets>' +
    '<div class="ub-img mr2" ticketsImg></div>' +
    '<div class="fs8">剩余</div>' +
    '<div class="fs8" auto="fstLeftSeats">0</div>' +
    '<div class="fs8 ml2 mr2">/</div>' +
    '<div class="fs8" auto="busLeftSeats">0</div>' +
    '<div class="fs8 ml2 mr2">/</div>' +
    '<div class="fs8" auto="encLeftSeats">0</div>' +
    '</div>' +
    '<div class="ub ub-ac mr16 uhide" ScheduleYlightDate style="font-family: arial;">' +
    '</div>' +
    '</div>' +
    '<div class="ub ub-ac mt4 pl16 pr16">' +
    '<div class="tx-c w50" auto="deptAirportName">——</div>' +
    '<div class="ub ub-f1 ub-ac pl2 pr2" line>' +
    '<div class="uba uc-a c24" style="width:0.47em;height:0.47em"></div>' +
    '<div class="ub-f2 ubt h0 uhide" showAt="alternate"></div>' +
    '<div class="ub-f2 ubt h0 uhide" showAt="return"></div>' +
    '<div class="ub-ac ub-pc fs103 c8 uhide pl3 pr3"  showAt="alternate" style="border:1px dashed;"></div>' +
    '<div class="ub-ac ub-pc c8 pl3 pr3 pt1 pb1 uhide"  showAt="return" style="border:1px dashed;">' +
    '<div class="img151 ub-img"></div>' +
    '</div>' +
    '<div class="ub-f2 dashed h0" style="border-bottom:1px dashed;"></div>' +
    '<div class="uba uc-a c31" style="width:0.47em;height:0.47em"></div>' +
    '</div>' +
    '<div class="tx-c  w50" auto="arrAirportName">——</div>' +
    '</div>' +
    '<div class="ub mt4 pl16 pr16">' +
    '<div class="ub ub-ver ub-ac tx-r pr2 c31">' +
    '<div class="ub ub-ac ub-f1 mb7">' +
    '<div class="mr3 fs8">计飞</div>' +
    '<div class="fs11" auto="std">--:--</div>' +
    '</div>' +
    '<div class="ub ub-ac ub-f1 " showAt="normal">' +
    '<div class="mr3 fs8">实飞</div>' +
    '<div class="c7 fs11" auto="atd">--:--</div>' +
    '</div>' +
    '</div>' +
    '<div class="ub ub-f1 ub-ver ub-ac ub-pc">' +
    '</div>' +
    '<div class="ub ub-ver ub-as ub-pe c31">' +
    '<div class="ub ub-as ub-f1 ub-pe mb7">' +
    '<div class="ub ub-ac">' +
    '<div class="mr3 fs8">计到</div>' +
    '<div class="fs11" auto="sta">--:--</div>' +
    '</div>' +
    '</div>' +
    '<div class="ub ub-ac ub-f1 ub-pe " showAt="normal">' +
    '<div class="mr3 fs8">实到</div>' +
    '<div class="c7 fs11" auto="ata">--:--</div>' +
    '</div>' +
    '</div>' +
    '</div>' +
    '<div id="div1" calss="uinn umar-a" style="margin-top:8px;margin-bottom:5px">' +
    '<div  class="ub uc-a1  c-wh t-bla umar-a tx-c">' +
    '<div basicInfo1  class="ub-f1 uinn t-wh uc-l1 uc-r1" style="background-color:#e2a271;border-right:solid 3px" >事件上报</div>' +
    '<div basicInfo2  class="ub-f1 uinn uc-r1 uc-l1 t-wh" style="background-color:#6695c4;border-left:solid 3px">事件确认<div show class="c-red" style="top:0.5em;right:0.5em;z-index:5;position:absolute;width:0.8em;font-weight:600;display:none;padding:1px">!</div></div>' +
    '</div>' +
    '</div>' +
    '</section>' +
    '</li>');
    forData(0);
    var elem;
    function forData(i){
        if (i < data.length) {
            	$.getJSON("js/clean/citys.png", function(jsons){
                var jso = jsons.array;
                var yes = 0;
                for (var j = 0; j < jso.length; j++) {
                    if (jso[j].apt3code == data[i].deptAirportName.toUpperCase()) {
                        data[i].deptAirportName = jso[j].aptallzhs;
                        yes++;
                    }
                    if (jso[j].apt3code == data[i].arrAirportName.toUpperCase()) {
                        data[i].arrAirportName = jso[j].aptallzhs;
                        yes++;
                    }
                    if (yes == 2) {
                        elem = html.clone(true).removeClass("uhide");
                        elem.attr({
                            "id": data[i].flightInfoId,
                            "std": data[i].std
                        });
                        flyList.setIcon(elem, data[i].carrier);
                        flyList.setTickets(elem, data[i].encLeftSeats);
                        iG.autoData(data[i], elem);
                        //            flyList.setFlightDate(elem,data[i].flightDate);  
                        elem.attr({
                            "deptBay": data[i].deptBay,//桥位
                            "fleetCode": data[i].fleetCode,//机号
                            "flightNo": data[i].flightNo,//航班号
                            "deptairPort": data[i].deptairPort,//起飞机场
                            "deptAirportName": data[i].deptAirportName,//起飞机场
                            "arrairPort": data[i].arrairPort,//到达机场
                            "arrAirportName": data[i].arrAirportName,//到达机场
                            "carrier": data[i].carrier,//承运公司
                            "tailno": data[i].tailno,//机型
                        });
						elem.find("[basicInfo1]").on("click", flyList.toFlyInfo1);
						if(data[i].isTrue==true){
							 elem.find("[show]").show();
						}
                        elem.find("[basicInfo2]").on("click", flyList.toFlyInfo2);
                        $("#list").append(elem);
                        i++;
                        forData(i);
                        break;
                    }
                }
            })
        }
        else {
            $.iBoxHide();
        }
    }
};

//设置图标
flyList.setIcon = function(elem, type){
    var carrier = {
        "MU": "img182",
        "FM": "img11",
        "KN": "img62"
    };
    elem.find("[icon]").addClass(carrier[type] || "img153");
}
//设置剩余票数
flyList.setTickets = function(elem, encLeftSeats){
    var color = "";
    var img = "";
    if (encLeftSeats <= 0) {
        color = "c8";
        img = "img135";
    }
    else {
        color = "c6";
        img = "img142";
    }
    elem.find("[tickets]").addClass(color);
    elem.find("[ticketsImg]").addClass(img);
}



//到航班信息
flyList.toFlyInfo1 = function(){
    var carrier = $(this).parent().parent().parent().parent().attr("carrier");
    var flightNo = $(this).parent().parent().parent().parent().attr("flightNo");
    var deptairPort = $(this).parent().parent().parent().parent().attr("deptairPort");
    var deptAirportName = $(this).parent().parent().parent().parent().attr("deptAirportName");
    var arrairPort = $(this).parent().parent().parent().parent().attr("arrairPort");
    var arrAirportName = $(this).parent().parent().parent().parent().attr("arrAirportName");
    var tailno = $(this).parent().parent().parent().parent().attr("tailno");
    var fleetCode = $(this).parent().parent().parent().parent().attr("fleetCode");
    var deptBay = $(this).parent().parent().parent().parent().attr("deptBay");
    var jsons = {
        "carrier": carrier,
        "flightNo": flightNo,
        "deptairPort": deptairPort,
        "deptAirportName": deptAirportName,
        "arrairPort": arrairPort,
        "arrAirportName": arrAirportName,
        "tailno": tailno,
        "fleetCode": fleetCode,
        "deptBay": deptBay
    };
    setStorage("pageJson", JSON.stringify(jsons));
    uexWindow.open("deepCleaning", 0, "deepCleaning.html", 2, "", "", "4", 280);
    return false;
}
//到航班信息
flyList.toFlyInfo2 = function(){
    var carrier = $(this).parent().parent().parent().parent().attr("carrier");
    var flightNo = $(this).parent().parent().parent().parent().attr("flightNo");
    var deptairPort = $(this).parent().parent().parent().parent().attr("deptairPort");
    var deptAirportName = $(this).parent().parent().parent().parent().attr("deptAirportName");
    var arrairPort = $(this).parent().parent().parent().parent().attr("arrairPort");
    var arrAirportName = $(this).parent().parent().parent().parent().attr("arrAirportName");
    var tailno = $(this).parent().parent().parent().parent().attr("tailno");
    var fleetCode = $(this).parent().parent().parent().parent().attr("fleetCode");
    var deptBay = $(this).parent().parent().parent().parent().attr("deptBay");
    var jsons = {
        "carrier": carrier,
        "flightNo": flightNo,
        "deptairPort": deptairPort,
        "deptAirportName": deptAirportName,
        "arrairPort": arrairPort,
        "arrAirportName": arrAirportName,
        "tailno": tailno,
        "fleetCode": fleetCode,
        "deptBay": deptBay
    };
    setStorage("pageJson", JSON.stringify(jsons));
    uexWindow.open("deepCleaningQuery", 0, "deepCleaningQuery.html", 2, "", "", "4", 280);
    return false;
}
